<template>
  <d2-container>
    <div class="flex-1 mt-2 ml-2">
      <div class="flex-1">
        <el-form :model="form" label-width="100px" ref="form">
          <div style="width: 45%;">
            <el-form-item :label="form.is_maintain == false ? '积分维护启用' : '积分维护关闭'" prop="is_maintain">
              <el-switch v-model="form.is_maintain"></el-switch>
            </el-form-item>
            <div class="font-s-1 text-light-muted tips">当开启积分维护时，须设置积分维护日期，当日会按维护积分设置扣除</div>
          </div>
          <!-- <div class="flex-1 mt-3">
            <div class="flex-1 row-ac">
              <el-form-item label="维护时间每月" prop="day">
                <div class="ml-2 row-ac">
                  <el-input v-model="form.day" style="width: 60px;"></el-input>
                  <div class="ml-1 mr-2">日</div>
                   <el-input v-model="form.hour" style="width: 60px;"></el-input>
                   <div class="ml-1">时</div>
                </div>
              </el-form-item>
            </div>
            <div class="font-s-1 text-light-muted tips">开户积分维护后，根据设置的时间和日期，每月到达时间后自动扣除积分进行维护</div>
          </div> -->
          <div class="mt-5 ml-5">
            <el-button size="small" type="primary" @click="submitForm">保 存</el-button>
          </div>

        </el-form>
      </div>
    </div>
  </d2-container>
</template>

<script>
  import {
    usersetListUrl,
    usersetDetailUrl,
    memberlevelListUrl,
    usersetCreateUrl,
    usersetUpdateUrl,
    usersetDeleteUrl,
  } from "@/utils/interface"
  export default {
    data() {
      return {
        form: {
          is_maintain: false,
          day: '',
          hour:''
        },
        setupStatus: false
      }
    },
    mounted() {
      this.getUsersetList()
    },
    methods: {
      getUsersetList() {
        this.$get(usersetListUrl).then(res => {
          if (res.data.code == 200) {
            this.usersetList = res.data.data.list
            if (this.usersetList.length == 0) {
              this.setupStatus = true
            } else {
              this.setupStatus = false
              this.setInfo = this.usersetList[0]
              this.setId = this.setInfo.id
              this.form = {
                is_maintain: this.setInfo.is_maintain ,
                day: this.setInfo.day,
                hour: this.setInfo.hour
              }
            }
          }
        })
      },
      submitForm() {
        if (this.setupStatus) {
          this.$post(usersetCreateUrl, this.form).then(res=>{
            if(res.data.code == 200){
              this.$message({
                type: 'success',
                message: '保存成功'
              });
            }
          })
        }else{
          this.$put(usersetUpdateUrl + this.setId + '/', this.form).then(res=>{
            if(res.data.code == 200){
              this.$message({
                type: 'success',
                message: '保存成功'
              });
            }
          })
        }
      }
    }
  }
</script>

<style>
  .tips {
    margin-left: 60px;
  }
</style>
